package com.zhanqiao.controller;

import com.zhanqiao.Utils.GetDataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;

public class TagController extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String mid= req.getParameter("mid");
        String tag=req.getParameter("tag");
        System.out.println(tag);

        DataSource dataSource=GetDataSourceUtil.getDataSource();
        QueryRunner queryRunner=new QueryRunner(dataSource);
        try {
            if(tag.equals("F")){
                queryRunner.update("UPDATE massage SET tag ='T' WHERE mid="+mid);
                System.out.println("更新成功"+"T");
            }else if(tag.equals("T")){
                queryRunner.update("UPDATE massage SET tag ='F' WHERE mid="+mid);
                System.out.println("更新成功"+"F");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
